package math;

public class Vec2{
	public float x;
	public float y;
	
	public Vec2(){
		x = 0;
		y = 0;
	}
	
	public Vec2(float x, float y){
		this.x = x;
		this.y = y;
	}
	
	public void Set(float x, float y){
		this.x = x;
		this.y = y;
	}
	
	public boolean Equals(Vec2 vec){
		if(x == vec.x && y == vec.y){
			return true;
		}else{
			return false;
		}
	}
	
	public Vec2 Add(Vec2 vec){
		Vec2 result = new Vec2();
		result.x = x + vec.x;
		result.y = y + vec.y;
		
		return result;
	}
	
	public Vec2 Subtract(Vec2 vec){
		Vec2 result = new Vec2();
		result.x = x - vec.x;
		result.y = y - vec.y;
		
		return result;
	}
	
	public Vec2 Multiply(float f){
		Vec2 result = new Vec2();
		result.x = x * f;
		result.y = y * f;
		
		return result;
	}
	
	public Vec2 Divide(float f){
		Vec2 result = new Vec2();
		result.x = x / f;
		result.y = y / f;
		
		return result;
	}
    
    public Vec2 Abs(){
        Vec2 result = new Vec2();
        result.x = Math.abs(x);
        result.y = Math.abs(y);
        
        return result;
    }
	
	public float Magnitude(){
		return (float)Math.sqrt(Math.pow(x, 2) + Math.pow(y, 2));
	}
	
	public Vec2 Normalise(){
		float mag = Magnitude();
		if(mag == 0){
			return this;
		}
		
		Vec2 result = new Vec2();
		result.x = x / mag;
		result.y = y / mag;
		
		return result;
	}
	
	public float Dot(Vec2 vec){
		return ((x  * vec.x) + (y  * vec.y));
	}

	public String toString() {
		return("X: " + x + " Y: " + y);
	}
}
